<template>
  <div>
    <TopFilter ref="formPanel" :list="topFilterList" :cols="3" :labelWidth="90" @filterChange="searchCustomer"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSubmitBtn="false"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      columnsRef="partPartOutboundPartSalesNetworkOrder"
      selectionType="single"
    ></FilterTable>
    <BaseDialog :visible.sync="action.visible" :title="action.title" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <networkOrderDetail @closeSalesDialog="action.visible = false" />
    </BaseDialog>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <div>
        <el-button type="primary" @click="closeDrawer(2)">接收</el-button>
        <el-button type="primary" @click="closeDrawer(2)">拒绝</el-button>
        <el-button @click="closeDrawer(1)">关 闭</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { customerDetail, customerType } from '@/api/part/partOut/partSales/index';
import networkOrderDetail from './networkOrderDetail';
export default {
  name: 'networkOrder',
  mixins: [dictionary],
  components: {
    networkOrderDetail
  },
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      fetchApi: customerDetail, // 调用接口
      fetchParams: { xhrAbort: false }, // 调用数据
      columns: this.createTablelist(),
      selectedRows: [],
      action: { title: '', visible: false, data: null }
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.queryCustomer();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName'
        },
        {
          type: 'INPUT',
          label: '客户手机',
          fieldName: 'mobile'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin'
        },
        {
          type: 'INPUT',
          label: '车牌号码',
          fieldName: 'license'
        }
      ];
    },
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close', true);
      } else {
        this.$emit('saveDialog', this.selectedRows);
      }
    },
    createTablelist() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 60,
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '网络订单单号',
          dataIndex: 'NETWORK_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '客户名称',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户手机号',
          dataIndex: 'MOBILE',
          sorter: true,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },

    editHandle(row) {
      this.action.title = '网络订单明细';
      this.action.visible = true;
      this.action.data = { ...row };
    },

    async queryCustomer() {
      // let res = await customerType();
      // this.topFilterList.find(item => item.fieldName === 'customerTypeCode').itemList = res.data.map(x => ({ text: x.CUSTOMER_TYPE_NAME, value: x.CUSTOMER_TYPE_CODE }));
    },

    searchCustomer(val) {
      const params = Object.assign({}, val, { xhrAbort: false });
      this.fetchParams = params;
    },

    // 选中
    selectChange(rows) {
      this.selectedRows = rows;
    }
  }
};
</script>
